package algorithm.sort;

/**
 * @author xutao
 * created 2020/3/16 13:02
 */
public class InsertionSort implements Sort {
    @Override
    public String name() {
        return "插入排序";
    }

    @Override
    public void sort(Integer[] arr) {
        for (int i = 1; i < arr.length; i++) {
            for (int j = i; j >0; j--) {
                if (arr[j]<arr[j-1]){
                    swap(arr,j-1,j);
                }else{
                    break;
                }
            }
        }
    }
}
